package com.etc.controller;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.etc.entity.SysOrder;
import com.etc.entity.SysOrderKey;
import com.etc.entity.SysUser;
import com.etc.model.SysOrderModel;
import com.etc.service.SysOrderService;
import com.etc.utils.DateTimeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


/**
 * 订单控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping("order")
public class SysOrderController {
	
	private  static final Logger log =LoggerFactory.getLogger(SysOrderController.class);
	
	@Autowired
	private SysOrderService sysorderService;

	@RequestMapping("order")
	public String user (){
		return "order";
	}


	@RequestMapping("orderAll")
	public String orderAll (HttpServletRequest request){
		request.setAttribute("orderconet",sysorderService.findByweiOrder().size());
		request.setAttribute("userOrder",sysorderService.findByAll());
		return "order";
	}


	/**
	 * 修改状态
	 * @param out
	 * @param id
	 * @param status
	 */
	@RequestMapping("updateStatus")
	public void dfasd(PrintWriter out,String id, String status){
		Integer rest = sysorderService.fds(Integer.valueOf(id),status);

		if(rest == 1){
			out.print(1);
		}else{
			out.print(2);
		}
	}


//	/**
//	 * 保存订单信息
//	 * @return
//	 * */
//	@RequestMapping("add")
//	@ResponseBody
//	public Integer saveOrder(SysOrder order){
//		order.setOrderNo(UUID.randomUUID().toString());
//		order.setOrderDate(String.valueOf(System.currentTimeMillis()));
//		int orderId = sysorderService.add(order);
//		return orderId;
//	}

	/**
	 * 更新订单信息
	 * @return
	 * */
	@RequestMapping("update")
	@ResponseBody
	public Integer updateOrder(SysOrder order){
		order.setOrderDate(String.valueOf(System.currentTimeMillis()));
		return sysorderService.update(order.getId().toString());
	}
	
	/**
	 * 删除订单信息
	 * @return
	 * */
	@RequestMapping("del")
	@ResponseBody
	public Integer deleteOrder(int id){
		return sysorderService.delete(id+"");
	}



}
